package work20250104;

/**
 * @author zdl
 * @date 2025/1/4
 */
class  Person{
    private String name;
    private int age;
    public void eat(){} //吃
    public void sleep(){}//睡
    public void fish(){
        System.out.println("钓鱼");
    };//钓鱼
    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "Peerson{name = " + name + ", age = " + age + "}";
    }
}
class  Student extends Person implements Fish{
    private String school;
    public void study(){}//学习

    @Override
    public void fish() {
        System.out.println("学生会钓鱼");
    }

    public Student(String school) {
        this.school = school;
    }

    public Student(String name, int age, String school) {
        super(name, age);
        this.school = school;
    }

    public Student() {
    }

    public String getSchool() {
        return school;
    }

    public void setSchool(String school) {
        this.school = school;
    }

    @Override
    public String toString() {
        return "Student{" +
                "school='" + school + '\'' +
                '}';
    }

    @Override
    public void diaoYu() {
        System.out.println("实现接口，学生钓鱼");
    }
}
class Teacher extends Person implements Fish{
    private String wordAddr;
    public void jiangKe(){};

    @Override
    public void fish() {
        System.out.println("老师会钓鱼");
    }

    public Teacher() {
    }

    public Teacher(String wordAddr) {
        this.wordAddr = wordAddr;
    }

    public Teacher(String name, int age, String wordAddr) {
        super(name, age);
        this.wordAddr = wordAddr;
    }

    public String getWordAddr() {
        return wordAddr;
    }

    public void setWordAddr(String wordAddr) {
        this.wordAddr = wordAddr;
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "wordAddr='" + wordAddr + '\'' +
                '}';
    }

    @Override
    public void diaoYu() {
        System.out.println("实现接口，老师钓鱼");
    }
}
class T{
    public void fish(Person person){
        person.fish();
    }
}
interface Fish{
    void diaoYu();
}
public class Demo8 {
    public static void main(String[] args) {
        /**
         * 3、使用抽象类和接口的面向对象思维设计如下类或接口,要求类要封装,不要求测试
         * 人：行为(吃、睡觉)、属性(姓名、年龄)
         * 	学生：行为(学习),属性(姓名,年龄,学校)
         * 	老师：行为(讲课),属性(姓名,年龄,工作单位)
         * 	经过几天学习后，学生和老师学会了钓鱼的行为(能力性质的形成接口)（20分）。
         * 要求: 类要封装
         * 提供对应的set , get方法,
         * 无参构造,有参构造方法,
         * 重写toString方法打印对象信息
         */
        //多态
        T t = new T();
        t.fish(new Student());
        t.fish(new Teacher());

        //实现接口
        new Student().diaoYu();
        new Teacher().diaoYu();
    }
}
